<template>
	<view class="_abbr">
		<view><u-search v-model="warehouseCode" @clickIcon="scanCode" @search="postShelv" @custom="postShelv"
				searchIcon="scan" :showAction="true" actionText="上架"></u-search></view>
		<view class="childId">{{workOrderId}}</view>
		<view>
			<view class="title"></view>
			<view class="_tbody">
				<view v-for="(item,index) in dataForm" :key="item.id">
					<view>{{item.parentCode}}/{{item.code}}</view>
					<view>
						<button size="mini" type="primary" @click="deleteItem(item)">下架</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import request from '@/utils/request';
	export default {
		name: 'detail',
		data() {
			return {
				warehouseCode: '',
				dataForm: [],
				workOrderId: '',
			}
		},
		onLoad(options) {
			uni.showLoading({
				title:'正在加载中'
			})
			this.workOrderId = options.workId;
			this.getData();
			uni.hideLoading()
		},
		methods: {
			scanCode() {
				uni.scanCode({
					success: (res) => {
						this.warehouseCode = res.result
						console.log(res.result);
						this.postShelv(res.result);
					}
				})
			},
			postShelv(value) {
				request({
					url: 'system/location',
					method: 'POST',
					data: {
						code: this.workOrderId,
						type: '4',
						parentCode: value,
						method: 'mini_bind'
					}
				}).then((res) => {
					if (res.code - 0 >= 500) {
						uni.showToast({
							title: '该仓库不存在',
							icon: 'error'
						})
					} else {
						this.getData();
					}
				})
			},
			// Shelves(value) {
			// 	this.postShelv(value)

			// },
			deleteItem(item) {
				const that = this;
				uni.showModal({
					title: '是否下架此工单，此操作结果将无法更改',
					success(res) {
						if (res.confirm) {
							request({
								url: `system/location/${item.id}`,
								method: 'DELETE',
							}).then(res => {
								that.getData()
							})
						}
					}
				})
			},
			getData() {
				request({
					url: `system/location/list`,
					data: {
						code: this.workOrderId
					}
				}).then(res => {
					console.log(res);
					this.dataForm.length = 0;
					this.dataForm = res.data;
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	._abbr {

		.childId {
			margin: 20rpx;
			text-align: center;
			font-size: large;
			font-weight: bolder;
			font-family: '楷体';
		}

		:nth-last-child(1) {
			._tbody {
				>view {
					border-bottom: 1px solid blueviolet;
					display: flex;
					justify-content: space-between;
					margin: 20rpx;
				}

			}

		}
	}
</style>